# coding=utf-8
# filter过滤列表，删除偶数，只保留奇数
def is_odd(n):
    return n % 2 == 1


L = filter(is_odd, [1, 2, 3, 4, 5, 6])
print(list(L))

# filter过滤列表，删除偶数，只保留奇数（用匿名函数实现）
L = filter(lambda n: n % 2 == 1, [1, 2, 3, 4, 5, 6])
print(list(L))


# filter序列中的空字符串删除
def not_empty(s):
    # strip()取出字符串首位指定信息
    return s and s.strip()


L = filter(not_empty, ["a", "b", "", None, " ", "C"])
print(list(L))
# filter序列中的空字符串删除（用匿名函数实现）
L = filter(lambda s: (s and s.strip()), ["a", "b", "", None, " ", "C"])
print(list(L))
